// pages/resume/resume.js
var app = getApp()
const { $Message } = require('../../../dist/base/index');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    flag: true,
    index: 0,
    index1: 0,
    date: 0,
    time:0,
    hiddenmodalput: true,
    optionTab: 0,
    aaa:-1,
    visible1: false,
    array1: ['笔试','面试','电话面试'],
    actions1: [
      {
        name: '全部下载',
        color: 'blue',
      },
      {
        name: '邀请面试',
        color: 'blue',
      },
      {
        name: '查看详请',
        color: 'blue',
      },
      {
        name: '不合适',
        // icon: 'share',
        color: 'red',
      }
    ],
    select: ['职位', '学校', '学历', '专业'],
    current: 'tab1',
    current_scroll: 'tab1',
    navbar: ['全部', '待筛选', '不合适'],
    currentTab: 0
  },
  bindPickerChange(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      index: e.detail.value
    })
  },
  //方式
  bindPickerChange1(e) {
    console.log('携带值为', e.detail.value)
    this.setData({
      index1: e.detail.value
    })
  },
  //日期
  bindDateChange(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date: e.detail.value
    })
  },
  //时间
  bindTimeChange(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      time: e.detail.value
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that=this;
    wx.request({
      url: 'http://www.recruit.com/api/enterprise/resumelists', // 仅为示例，并非真实的接口地址
      header: {
        'content-type': 'application/json' // 默认值
      },
      success(res) {
        that.setData({list:res.data.data})
        console.log(res.data)
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
     
  },
  navbarTap: function (e) {
    console.log(e.currentTarget.dataset.idx)
    var that = this;
    if (e.currentTarget.dataset.idx==2){
      var url ="http://www.recruit.com/api/enterprise/resumenolist";
    } else if (e.currentTarget.dataset.idx == 0){
      var url = "http://www.recruit.com/api/enterprise/resumelists";
    }else{
      var url = "http://www.recruit.com/api/enterprise/resumelist";
    }
    wx.request({
      url: url, // 仅为示例，并非真实的接口地址
      header: {
        'content-type': 'application/json' // 默认值
      },
      success(res) {
        that.setData({ list: res.data.data })
        console.log(res.data)
      }
    })
    this.setData({
      currentTab: e.currentTarget.dataset.idx
    })
  },
  selectTap: function (e) {
    console.log(e);
    var that=this;
    var idx = e.currentTarget.dataset.idx;
    switch(idx){
      case 0: var url ="http://www.recruit.com/api/enterprise/positions";var key='position_name';break;
      case 1: var url = "http://www.recruit.com/api/enterprise/schoollist"; var key = 'u_school';break;
      case 2: var url='';break;
      case 3: var url = "http://www.recruit.com/api/enterprise/majorlist"; var key = 'u_major';break;
    }
    if(url!=''){
      wx.request({
        url: url, // 仅为示例，并非真实的接口地址
        header: {
          'content-type': 'application/json' // 默认值
        },
        success(res) {
          console.log(res.data);
          that.setData({ array: res.data.data, key: key})
          that.onLoad()
          console.log(that.data);
        }
      });
    }else{
      var array = ['本科', '大专'];
      that.setData({array:array,key:''})
    }
    this.setData({
      optionTab: e.currentTarget.dataset.idx
    })
  },
  handleOpen1(e) {
    var that = this;
    var idx = e.currentTarget.dataset.idx;
    if (e.currentTarget.dataset.idx === this.data.aaa) {
      this.setData({ aaa: -1, resumeId: -1 });
      return false;
    }
    this.setData({
      visible1: true,
      aaa: e.currentTarget.dataset.idx,
      id: that.data.list[idx]['id']
    });
  },
  handleCancel1() {
    this.setData({
      visible1: false
    });
  },
  handleClickItem1(e){
    var index=e.detail.index;
    var id=this.data.id;
    switch(index){
      //下载
      case 0: ; break;
      //邀请面试
      case 1: this.setData({ flag: false, visible1: false });break;
      //查看详情
      case 2: wx.navigateTo({url: '/pages/self/resumeShow/resumeShow?id='+id});break;
      //不合适
      case 3: this.setData({ hiddenmodalput:false});
    }
  },
  //邀约表单提交
  formsubmit:function(e){
    //面试方式
    var model=parseInt(this.data.index1)+1;
    //面试日期+时间
    var datetime=this.data.date+' '+this.data.time;
    //id
    var id=this.data.id;
    var that=this;
    var arr={'interview_site':e.detail.value.interview_site,'interview_model':model,'interview_time':datetime,'ids':id};
    console.log(arr);
    wx.request({
      url: 'http://www.recruit.com/api/enterprise/inviteadd', // 仅为示例，并非真实的接口地址
      data:arr,
      method:"POST",
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值
      },
      success(res) {
        if(res.data.code==200){
          that.setData({ flag: true })
          wx.showToast({
            title: '邀约成功',
            icon: 'success',
            duration: 2000
          })
          
        }else{
          that.setData({ flag: true })
          wx.showToast({
            title: '邀约失败，可能已被拒绝',
            icon: 'none',
            duration: 2000
          })
        }
        
        console.log(res.data)
      }
    })
  },
  // 遮罩层显示
  show: function () {
    this.setData({ flag: false })
  },
  // 遮罩层隐藏
  conceal: function () {
    this.setData({ flag: true })
  },










  //点击按钮痰喘指定的hiddenmodalput弹出框  
  modalinput: function () {
    this.setData({
      hiddenmodalput: !this.data.hiddenmodalput
    })
  },
  //取消按钮  
  cancel: function () {
    this.setData({
      hiddenmodalput: true
    });
  },
  //确认   不合适  
  confirm: function () {
    var connect=this.data.connect;
    var id=this.data.id;
    var that=this;
    wx.request({
      url: 'http://www.recruit.com/api/enterprise/resumedels', // 仅为示例，并非真实的接口地址
      data: {connect:connect,ids:id},
      method:'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值
      },
      success(res) {
        that.setData({
          hiddenmodalput: true,
          visible1: false
        })
        getCurrentPages()[getCurrentPages().length - 1].onShow();
      }
    })
  },
  formName: function (e) {
    this.setData({
      connect: e.detail.value
    })
  },
  p1:function (e){
    
  }
})